package com.monster.dao;

import com.monster.pojo.Tag;

import java.sql.SQLException;
import java.util.ArrayList;

public class TagDaoImpl extends BaseDao implements TagDao {
    @Override
    public ArrayList<Tag> FindTagbyid(long id) {
        ArrayList<Tag> taglist = new ArrayList<Tag>();
        String sql = "select * from tag where tag_id";
        Object[] obj = {id};
        rs = this.executeQuery(sql, obj);
        try {
            while(rs.next()){
                Tag tag = new Tag();
                tag.setTagId(rs.getLong(1));
                tag.setTagName(rs.getString(2));
                tag.setTagType(rs.getString(3));
                taglist.add(tag);

            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return taglist;
    }
    /**
     * 根据歌单id查询标签集合
     * @param playlistId
     * @return 标签集合
     */
    public ArrayList<Tag> listTagsByPlaylistId(Long playlistId) {
        ArrayList<Tag> tags = new ArrayList<>();
        String sql = "SELECT * FROM tag t LEFT JOIN playlist_tag pt ON pt.tag_id=t.tag_id WHERE playlist_id=?";
        Object[] obj = {playlistId};
        rs = executeQuery(sql, obj);
        try {
            while (rs.next()) {
                Tag tag = new Tag();
                tag.setTagId(rs.getLong("tag_id"));
                tag.setTagName(rs.getString("tag_name"));
                tag.setTagType(rs.getString("tag_type"));
                tags.add(tag);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return tags;
    }


}
